home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_6.zip / EDIT.C < prev    next >
C/C++ Source or Header  |  1993-12-01  |  24KB  |  823 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* edit.c */
  21.  
  22. #include "externs.h"
  23.  
  24.  
  25. int AVL_COL()
  26. {
  27.     AVL_EDIT_WINDOW_PTR w;
  28.     int i, j = 0, n, n2 = 0;
  29.     char *t, line [30];
  30.     w = &avl_windows[avl_window];
  31.     t = w -> current_line -> line;
  32.     n = strlen(t);
  33.     for(i = 0; i <= w -> txt_col; ++i)  {
  34.         if (*(t + i) == '\t' && i != w -> txt_col)  {
  35.             for (n2= 0; !(((j + 1) % w -> tabsize) == 0); ++n2)    
  36.                 j++;
  37.             j++;
  38.             }
  39.         else 
  40.             j++;
  41.         }
  42.     return j;
  43. }
  44.  
  45.  
  46.  
  47. void AVL_JOIN_RIGHT() /* Join current line with next */
  48. {
  49.     AVL_EDIT_WINDOW_PTR w;
  50.     AVL_LINE_PTR temp, temp2;
  51.     struct rccoord old;
  52.     int pos, pos2;
  53.     w = &avl_windows[avl_window];
  54.     if (w -> current_line -> next != w -> head)  {
  55.         pos2 = w -> txt_col;
  56.         if ((strlen(w -> current_line -> line) + strlen(w -> current_line -> next -> line)) >= AVL_MAX_LINEL)  {
  57.             AVL_ERROR("Lines are too long. Can't perform join!");
  58.             return;
  59.             }
  60.         if (w -> scr_row < (w -> r2 - w -> r1 + 1))  {
  61.             old = _settextposition(w -> scr_row+1,w -> scr_col);
  62.             AVL_DELETE_LINE();
  63.             }
  64.         else
  65.             old = _settextposition(w -> scr_row,w -> scr_col);
  66.         
  67.         temp = w -> current_line -> next;
  68.         strcat(w -> current_line -> line,temp -> line);
  69.         w -> current_line -> next = temp -> next;
  70.         temp -> next -> previous = w -> current_line;
  71.         AVL_MAKE_NUMBER();
  72.         free(temp);
  73.         pos = w -> scr_row;
  74.         temp = temp2 = w -> current_line;
  75.         while (++pos != (w -> r2 - w -> r1 + 1) && temp -> next != w -> head)    {
  76.             temp = temp -> next;
  77.             }
  78.         if (pos == (w -> r2 - w -> r1 + 1) && temp != w -> head)  {
  79.             w -> current_line = temp;
  80.             w -> scr_row = w -> r2 - w -> r1 + 1;
  81.             _settextposition( w -> scr_row, 1);
  82.             AVL_UPDATE_LINE();
  83.             }
  84.         w -> current_line = temp2;
  85.         old = _settextposition(w -> scr_row = old.row,w -> scr_col = old.col);
  86.         w -> txt_col = pos2;
  87.         w -> changed = 1;
  88.         AVL_UPDATE_LINE();
  89.         }
  90. }        
  91.  
  92. void AVL_JOIN_LEFT() /* Join current line with Previos */
  93. {
  94.     AVL_EDIT_WINDOW_PTR w;
  95.     AVL_LINE_PTR temp, temp2;
  96.     struct rccoord old;
  97.     int pos, pos2;
  98.     w = &avl_windows[avl_window];
  99.     if (w -> current_line -> previous != w -> head)  {
  100.         if ((strlen(w -> current_line -> line) + strlen(w -> current_line -> previous -> line)) >= AVL_MAX_LINEL)  {
  101.             AVL_ERROR("Lines are too long. Can't perform join!");
  102.             return;
  103.             }
  104.         old = _settextposition(w -> scr_row+1,w -> scr_col);
  105.         temp = w -> current_line;
  106.         w -> current_line = w -> current_line -> previous;
  107.         AVL_CURSOR_END();
  108.         pos2 = w -> txt_col;
  109.         strcat(w -> current_line -> line, temp -> line);
  110.         w -> current_line -> next = temp -> next;
  111.         temp -> next -> previous = w -> current_line;
  112.         AVL_MAKE_NUMBER();
  113.         free(temp);
  114.         if (w -> scr_row != 1)
  115.             AVL_DELETE_LINE();
  116.         pos = w -> scr_row;
  117.         temp = temp2 = w -> current_line;
  118.         while (++pos != (w -> r2 + 1) && temp -> next != w -> head)    {
  119.             temp = temp -> next;
  120.             }
  121.         if (pos == (w -> r2 + 1) && temp != w -> head)  {
  122.             w -> current_line = temp;
  123.             w -> scr_row = (w -> r2 - 1);
  124.             _settextposition( (w -> r2 - 1), 1);
  125.             AVL_UPDATE_LINE();
  126.             }
  127.         w -> current_line = temp2;
  128.         if (old.row > 1)
  129.             old = _settextposition(w -> scr_row = old.row - 1,w -> scr_col = old.col);
  130.         else
  131.             old = _settextposition(w -> scr_row = old.row,w -> scr_col = old.col);
  132.         w -> txt_col = pos2;
  133.         AVL_UPDATE_LINE();
  134.         w -> changed = 1;
  135.         }
  136. }        
  137.  
  138.  
  139. int AVL_OFFSET()
  140. {
  141.     AVL_EDIT_WINDOW_PTR w;
  142.     int n, i, off = 0;
  143.     w = &avl_windows[avl_window];
  144.     n = AVL_COL();
  145.     off = 0;
  146.     for(i = (w -> c2 - w -> c1 + 1); i < n; i += 20)
  147.         off += 20;
  148.     return ( off );
  149. }
  150.  
  151. int AVL_COUNT()
  152. {
  153.     int i = 0;
  154.     AVL_EDIT_WINDOW_PTR w;
  155.     w = &avl_windows[avl_window];
  156.     avl_line_temp = w -> current_line;
  157.     for (; avl_line_temp != w -> head 
  158.            && i < w -> r2; avl_line_temp = avl_line_temp -> next)
  159.         ++i;
  160.     avl_line_temp = avl_line_temp -> previous;
  161.     return i;
  162. }
  163.  
  164. void AVL_OPEN_LINE()
  165. {
  166.    short left, top, right, bottom;
  167.    struct rccoord rc;
  168.  
  169.    _gettextwindow( &top, &left, &bottom, &right );
  170.    rc = _gettextposition();
  171.    _settextwindow( rc.row+1, left, bottom, right );
  172.    _scrolltextwindow( _GSCROLLDOWN );
  173.    _settextwindow( top, left, bottom, right );
  174.    _settextposition( rc.row+1, rc.col );
  175. }
  176.  
  177. void AVL_EDIT_ENTER()
  178. {
  179.     AVL_EDIT_WINDOW_PTR w;
  180.     AVL_LINE_PTR temp;
  181.     struct rccoord old;
  182.     short i, j, k;
  183.     old = _gettextposition();
  184.     w = &avl_windows[avl_window];
  185.     for(i = 0, j = 0; w -> current_line -> line [i] == ' '; ++i);
  186.     j = i;
  187.     temp = calloc(1,sizeof(AVL_LINE_SIZE));
  188.     temp -> previous = w -> current_line;
  189.     temp -> next     = w -> current_line -> next;
  190.     w -> current_line -> next -> previous = temp;
  191.     w -> current_line -> next = temp;
  192.     strcpy(temp -> line, w -> current_line -> line + w -> txt_col);
  193.     w -> current_line -> line [w -> txt_col] = '\0';
  194.     AVL_MAKE_NUMBER();
  195.     w -> txt_col = 0;
  196.     AVL_OPEN_LINE();
  197.     _settextposition(w -> scr_row,w -> scr_col = 1);
  198.     AVL_UPDATE_LINE();
  199.     if (w -> scr_row == (w -> r2 - w -> r1 + 1)) 
  200.         _scrolltextwindow( 1 );
  201.     else
  202.         w -> scr_row += 1;
  203.     w -> current_line = temp; 
  204.     w -> changed = 1;
  205.     if (strlen(temp -> line) > 0)
  206.         j = 0;  
  207.     for(i = 0; i < j; ++i)
  208.         w -> current_line -> line[i] = ' ';
  209.     if (j > 0)
  210.         w -> current_line -> line[i] = '\0';
  211.     _settextposition(w -> scr_row,w -> scr_col = (j < 78) ? j + 1 : 1);
  212.     w -> txt_col = (j < 78) ? j : 0;
  213.     AVL_UPDATE_LINE();
  214.     if (w -> offset != 0)  {
  215.         w -> offset = 0;
  216.         AVL_SCROLL();
  217.         }
  218. }
  219.  
  220. void AVL_SCROLL()
  221. {
  222.     AVL_EDIT_WINDOW_PTR w;
  223.     AVL_LINE_PTR temp;
  224.     struct rccoord old;
  225.     short i, j, k;
  226.     AVL_WIN_PTR t, t2;
  227.     w = &avl_windows[avl_window];
  228.     old = _gettextposition();
  229.     temp = w -> current_line;
  230.     j = old.row;
  231. /*
  232.     if ((w -> txt_col == strlen(temp -> line)) && (w -> txt_col > 0))
  233.         w -> txt_col -= 1;
  234. */
  235.     k = w -> txt_col;
  236.     for(i = j; i > 1; --i)  {
  237.         w -> current_line = w -> current_line -> previous;
  238.         }
  239.     w -> scr_row = 1;
  240.     avl_hscroll_on = 1;
  241.     _settextposition(1,1);
  242.     AVL_UPDATE_SCREEN();
  243.     _settextposition(old.row,old.col);
  244.     w -> current_line = temp;
  245.     w -> scr_row = j;
  246.     w -> scr_col = old.col;
  247.     w -> txt_col = k;
  248.     avl_hscroll_on = 0;
  249.     AVL_UPDATE_CURSOR();
  250. }
  251.  
  252.  
  253.  
  254. void AVL_UPDATE_STATUS_LINE()
  255. {
  256.     AVL_EDIT_WINDOW_PTR w;
  257.     char status[10];
  258.     char line[181];
  259.     char fn[121];
  260.     short att, attold;
  261.     short i, n;
  262.     char *p;
  263.     w = &avl_windows[avl_window];
  264.     attold = _gettextcursor();
  265.     if (w -> no_status == 'N') return;
  266.     if (avl_window < AVL_MAX_WINDOWS)
  267.         switch (tolower(w -> edit_mode))  {
  268.             case 'x' : strcpy(status,"Ovr"); att = 0x0007; break;
  269.             case 'i' : strcpy(status,"Ins"); att = 0x0707; break;
  270.             default  : w -> edit_mode = 'i'; strcpy(status,"Ins"); att = 0x0707; break;
  271.             }
  272.     else
  273.         strcpy(status,"Hlp");
  274.     AVL_MAKE_FN(fn, w -> file_name);
  275.     sprintf(line,"Line %3d Col %2d %-35s %s %-12s F1-Help             "
  276.         ,  w -> current_line -> line_no - 1
  277.         , w -> txt_col + 1
  278.         , avl_message
  279.         , status
  280.         , fn
  281.         );
  282.     n = strlen(line);
  283.     if (n > 80) n = 80;
  284.     p = line;
  285.     for(i = 1; i <= n; ++i, ++p)
  286. /*        AVL_PUT(*p,w -> r1 - 1,i,avl_sta_bk_color,avl_sta_color);   */
  287.         AVL_WVIDEO(*p,(unsigned char) (avl_sta_bk_color << 4 | avl_sta_color)
  288.             , AVL_MAP(w -> r1 - 1,i));
  289.     if (attold != att)
  290.         _settextcursor(att);    
  291. }
  292.  
  293.  
  294. void AVL_INIT_WINDOW(AVL_EDIT_WINDOW_PTR w, AVL_LINE_PTR first)
  295. {
  296.     short att;
  297.     att = _settextcursor(0x